import React, {useEffect, useState} from 'react'
import {Form} from 'antd'
import type {UploadFile} from 'antd/es/upload/interface'
import styles from './index.less'
import CustomUpload from '@/components/Upload'
import OtherUpload from './OtherUpload'

const qualifications = (props: any) => {
	const {enclosureList, type} = props
	const [fileList, setFileList] = useState<UploadFile[]>([])
	const [urlData, setUrlData] = useState<{}>({})

	const uploadDom = (targetAttr: number) => {
		const uploadProps: any = {
			key: targetAttr,
			text: '暂无文件',
			modelName: 'spAccess',
			targetAttr,
			callback: () => {},
		}
		const newData = enclosureList?.find(
			(item: {targetAttr: number}) => item?.targetAttr === targetAttr,
		)
		if (newData) {
			uploadProps.fileList = [
				{
					uid: newData?.targetAttr?.toString(),
					name: newData?.filename,
					url: newData?.url,
				},
			]
		}

		return (
			<>
				<CustomUpload {...uploadProps} />
			</>
		)
	}
	useEffect(() => {
		const arr: any = []
		enclosureList?.forEach((item: any) => {
			if (item?.targetAttr === 31) {
				arr.push({
					uid: item?.id,
					name: item?.filename,
					url: item?.url,
				})
			}
		})
		setFileList(arr)
	}, [enclosureList])

	return (
		<div className={styles.qualifications}>
			<Form name="basic" autoComplete="off" disabled>
				{type === 'DYY_GYS' ? (
					<table border="1" className={styles.uploadWrap}>
						<tr>
							<td>人员组织结构</td>
							<td>{uploadDom(23)}</td>
							<td>社会保险登记证</td>
							<td>{uploadDom(24)}</td>
							<td>社保缴费凭证</td>
							<td>{uploadDom(25)}</td>
						</tr>
						<tr>
							<td>最近财务报表</td>
							<td>{uploadDom(26)}</td>
							<td>最新税务申报表</td>
							<td>{uploadDom(27)}</td>
							<td>公司设计诉讼/仲裁情况</td>
							<td>{uploadDom(28)}</td>
						</tr>
						<tr>
							<td>公司设计的行政处罚情况</td>
							<td>{uploadDom(29)}</td>
							<td>交易合同价值配套的抵押物</td>
							<td>{uploadDom(30)}</td>
						</tr>
						<tr>
							<td colSpan={6}>
								<OtherUpload
									targetAttr={31}
									urlName="otherFileUrl"
									fileList={fileList}
									setFileList={setFileList}
									enclosureList={enclosureList}
									urlData={urlData}
									setUrlData={setUrlData}
								/>
							</td>
						</tr>
					</table>
				) : (
					''
				)}
				{type === 'SP_GYS' ? (
					<table border="1" className={styles.uploadWrap}>
						<tr>
							<td>营业执照</td>
							<td>{uploadDom(1)}</td>
							<td>开户许可证</td>
							<td>{uploadDom(2)}</td>
							<td>保密承诺函</td>
							<td>{uploadDom(3)}</td>
						</tr>
						<tr>
							<td>法人身份证</td>
							<td>{uploadDom(4)}</td>
							<td>企业法人征信报告</td>
							<td>{uploadDom(5)}</td>
							<td>廉洁声明</td>
							<td>{uploadDom(7)}</td>
						</tr>
						<tr>
							<td>供应商道德行为规范承诺书</td>
							<td>{uploadDom(9)}</td>
							<td>经营场地证明及场地照片</td>
							<td>{uploadDom(10)}</td>
							<td>保证金认款单截图</td>
							<td>{uploadDom(12)}</td>
						</tr>
						<tr>
							<td colSpan={6}>
								<OtherUpload
									uploadType="DDUpload"
									fileList={fileList}
									setFileList={setFileList}
									enclosureList={enclosureList}
									urlData={urlData}
									setUrlData={setUrlData}
								/>
							</td>
						</tr>
					</table>
				) : (
					''
				)}
				{type !== 'SP_GYS' && type !== 'DYY_GYS' ? (
					<table border="1" className={styles.uploadWrap}>
						<tr>
							<td>营业执照</td>
							<td>{uploadDom(1)}</td>
							<td>开户许可证</td>
							<td>{uploadDom(2)}</td>
							<td>保密承诺函</td>
							<td>{uploadDom(3)}</td>
						</tr>
						<tr>
							<td>法人身份证</td>
							<td>{uploadDom(4)}</td>
							<td>企业法人征信报告</td>
							<td>{uploadDom(5)}</td>
							<td>供应商登记表</td>
							<td>{uploadDom(6)}</td>
						</tr>
						<tr>
							<td>廉洁声明</td>
							<td>{uploadDom(7)}</td>
							<td>供应商道德行为规范</td>
							<td>{uploadDom(8)}</td>
							<td>供应商道德行为规范承诺书</td>
							<td>{uploadDom(9)}</td>
						</tr>
						<tr>
							<td>经营场地证明及场地照片</td>
							<td>{uploadDom(10)}</td>
							<td>合同扫描件</td>
							<td>{uploadDom(11)}</td>
							<td>保证金认款单截图</td>
							<td>{uploadDom(12)}</td>
						</tr>
						<tr>
							<td colSpan={6}>
								<OtherUpload
									uploadType="DDUpload"
									fileList={fileList}
									setFileList={setFileList}
									enclosureList={enclosureList}
									urlData={urlData}
									setUrlData={setUrlData}
								/>
							</td>
						</tr>
					</table>
				) : (
					''
				)}
			</Form>
		</div>
	)
}

export default qualifications
